package pers.xiaoliang.concurrency.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Jedis;

/**
* @description: 测试redis
* @author: xiaoliang.liu
* @date: 2018/7/29 17:26
* @version v1.0
*/
@Slf4j
@Controller
@RequestMapping("redis")
public class TestRedisController {

    /** redis客户端工具 */
    private final Jedis jedis;

    @Autowired
    public TestRedisController(Jedis jedis) {
        this.jedis = jedis;
    }

    /**
     * 根据key从redis中获取value值
     * @param key key值
     * @return value
     */
    @ResponseBody
    @GetMapping("get")
    public String get(@RequestParam("key") String key) {
        return jedis.get(key);
    }

    /**
     * 设置值到redis中
     * @param key key值
     * @param value value值
     * @return String
     */
    @ResponseBody
    @PostMapping("set")
    public String set(@RequestParam("key") String key, @RequestParam("value") String value) {
        return jedis.set(key, value);
    }
}
